package com.wkh.datastructure.BinaryTree;

/**
 * 对称二叉树
 */
public class SymmetricBinaryTree {
    public static void main(String[] args) {
        TreeNode root = new TreeNode(1,
               null,null);
        boolean flag = isSymmetric(root);
        System.out.println(flag);
    }
    //判断二叉树是否对称
    public static boolean isSymmetric(TreeNode root){
        return check(root.left,root.right);
    }

    private static boolean check(TreeNode left, TreeNode right) {
        if (left == null && right == null){
            return true;
        }
        if (right == null || left == null){
            return false;
        }
        if (left.value != right.value){
            return false;
        }
        return check(left.left,right.right)&&check(left.right,right.left);
    }
}
